
public class BankSystem {
	public static void main(String[] args) {
		BankSysControl ctrl = new BankSysControl();
		
		
		Login l = new Login();
		boolean authed=false;
		String retMsg;
		while(!authed){
			//Get information for Login
			String user=ctrl.getUserName(); //get username
			l.setUser(user);
			String pass=ctrl.getPassword(); //get password
			l.setPass(pass);
			//attempt to login
			retMsg=l.authenticate();
			//if successful exit, otherwise re-attempt authentication
			if(retMsg.equals("\nLogin Successful.\n"))
				authed=true;
			ctrl.printMessage(retMsg);
		}
		int perms=l.getPermissions();
		int userID=l.getUserID();
		//initialize bank account(s) from database
		BankAccount[] accessibleAccounts=AbsDatabase.getAccounts(userID, perms);
		boolean running=true;
		BankAccount currAccount;

		while(running){	
			currAccount=ctrl.displayAvailableAccountsMenu(accessibleAccounts);
			int menuSelection;
			boolean editingCurrAccount=true;
			if(currAccount==null){
				editingCurrAccount=false;
				running=false;
			}
			ctrl.clearConsole();
			while(editingCurrAccount){
				menuSelection=ctrl.displayAccountMenu(perms,currAccount.getAccountNum(),currAccount.getOwnerName(),currAccount.getNickName(),currAccount.getOwnerID(),currAccount.getAccountType(),currAccount.getBalance(),currAccount.getInterestRate());		//display the menu for your permissions
				switch (menuSelection){
					case 1:
						currAccount.deposit(ctrl.getDepositAmount());
						ctrl.displayBalance(currAccount.getBalance());
						break;
					case 2:
						try{
							currAccount.withdraw(ctrl.getWithdrawAmount());
						}catch(Exception e){
							ctrl.printMessage(e.getMessage());
						}
						ctrl.displayBalance(currAccount.getBalance());
						break;
					case 3:
						currAccount.setInterestRate(ctrl.getNewInterestRate());
						ctrl.notifyInterestRate(currAccount.getInterestRate());
						break;
					case 4:
						currAccount.addInterest();
						ctrl.displayBalance(currAccount.getBalance());
						break;
					case 5:
						editingCurrAccount=false;
						break;
				}
			
			}
			ctrl.clearConsole();
		}
		
	}
}
